//window.onresize=function(){
//	var t_width=document.body.scrollWidth;
//	if(t_width<1601){
//		$("#kf").hide();
//		$("#zhul_backbg").hide();
//	}else{
//		$("#kf").show();
//		$("#zhul_backbg").show()
//	}
//}
// JavaScript Document
$(document).ready(function(){
	/*用户名hover*/
	$("#mylname").mouseover(function(){
		$("#mylname_menu").show();
	}).mouseout(function(){
		$("#mylname_menu").hide();
	});
	/*导航hover*/
	/*
	$("#daohang").mouseover(function(){
		$("#mymap_menu").show();
	}).mouseout(function(){
		$("#mymap_menu").hide();
	});
	*/
	//帖子详细页，鼠标经过楼层 底部字体颜色加深
	$(".zhul_xx_louzhu").mouseover(function(){
		$(this).find(".zhul_xx_botcz").addClass("zhul_cz_hv");
	}).mouseout(function(){		
		$(this).find(".zhul_xx_botcz").removeClass("zhul_cz_hv");
	});
	//展开详细-介绍
	$(".zhul_lts_jianjie").click(function(){
		$(this).find(".zhul_zkxx_con").show();
	});
	/*添加标签*/
	$(".zhul_tz_addbq").click(function(){
		$(this).find(".zhul_addtag_bg").show();
	});
	/*发新帖2-邀请好友hover*/
	$(".zhul_ft_yaoqing li").mouseover(function(){
		$(this).addClass("zhul_ft_yqHv");
		$(this).find(".zhul_ft_check").show();
	}).mouseout(function(){
		$(this).removeClass("zhul_ft_yqHv");
		$(this).find(".zhul_ft_check").hide();
	});
	/*nav 分类hover*/
	$(".zhul_sy_zyfl").mouseover(function(){
		$(".zhul_sy_sort").attr("over",1);
		$(this).addClass("zhul_nav_flhv");		
		$(this).find("#flname").removeClass("zhul_sy_navHv");
		$(this).find(".zhul_sy_sort").show();
	}).mouseout(function(){
		$(".zhul_sy_sort").attr("over",2);
		var btn=this;
		setTimeout(function(){
			if($(".zhul_sy_sort").attr("over")==2){
				$(btn).removeClass("zhul_nav_flhv");
				$(btn).find("#flname").addClass("zhul_sy_navHv");
				$(btn).find(".zhul_sy_sort").hide();
			}
		}, 100);		
	});
	$(".zhul_sy_zyfl2").mouseover(function(){
		$(".zhul_sy_sort2").attr("over",1);
		$(this).addClass("zhul_nav_flhv");		
		$(this).find("#flname").removeClass("zhul_sy_navHv");
		$(this).find(".zhul_sy_sort2").show();
	}).mouseout(function(){
		$(".zhul_sy_sort2").attr("over",2);
		var btn=this;
		setTimeout(function(){
			if($(".zhul_sy_sort2").attr("over")==2){
				$(btn).removeClass("zhul_nav_flhv");
				$(btn).find("#flname").addClass("zhul_sy_navHv");
				$(btn).find(".zhul_sy_sort2").hide();
			}
		}, 100);		
	});
	/*更换模版切换*/
	$(".zjil_temp_top a").eq(0).addClass("zhul_tempHv");
	$(".zjil_temp_top a").click(function(){
		$(".zhul_setTemplate").hide();
		$(".zjil_temp_top a").removeClass("zhul_tempHv");
		$(this).addClass("zhul_tempHv");
		var index=$(".zjil_temp_top a").index($(this));
		$(".zhul_setTemplate:eq("+index+")").show();
	});
	/*header成员主题数量hover*/
	$(".zhul_lts_Rshuju li").mouseover(function(){
		$(this).find("span").addClass("zhul_lts_sjHv");
	}).mouseleave(function(){
		$(this).find("span").removeClass("zhul_lts_sjHv");	
	});
	/*已加热hover*/
	$(".zhul_xx_alhot").mouseover(function(){
		$(this).find(".zhul_xx_lqxhot").show();
	}).mouseout(function(){
		$(this).find(".zhul_xx_lqxhot").hide();
	});
	/*已收集hover*/
	$(".zhul_xx_alshouji").mouseover(function(){
		$(this).find(".zhul_xx_lqxhot").show();
	}).mouseout(function(){
		$(this).find(".zhul_xx_lqxhot").hide();
	});
	/*已加入hover*/
	$("#al_jiar").mouseover(function(){
		$(this).find("img").attr("src","/img/indeximg/zhul_edit_xzu.gif");
	}).mouseout(function(){
		$(this).find("img").attr("src","/img/indeximg/zhul_al_jiaru.gif");
	});
	/*邀请好友hover*/
	$(".zhul_yq_hylist li").live("mouseover",function(){
		$(this).css('background','#6cc5ec');
		$(this).find(".zhul_yq_hyname").css('color','#ffffff');
		$(this).find(".zhul_yq_rchecked img").attr('src','/img/indeximg/zhul_yq_checked2.gif');
	}).live("mouseout",function(){
		$(this).css('background','#fafafa');
		$(this).find(".zhul_yq_hyname").css('color','#444444');
		$(this).find(".zhul_yq_rchecked img").attr('src','/img/indeximg/zhul_yq_checked.gif');
	});
	/*群组首页tab切换*/
	tab_even('zytab1','zhul_qz_flhv','zhul_qz_zyshow1');
	tab_even('zytab2','zhul_qz_flhv','zhul_qz_zyshow2');
	tab_even('zytab3','zhul_qz_flhv','zhul_qz_zyshow3');
	tab_even('zytab4','zhul_qz_flhv','zhul_qz_zyshow4');
	tab_even('zytab5','zhul_qz_flhv','zhul_qz_zyshow5');
	tab_even('zytab6','zhul_qz_flhv','zhul_qz_zyshow6');
	/*成员hover*/
	$(".zhul_cy_newslist li").mouseover(function(){
		$(this).find(".zhul_ft_zshu a").css("color","#0c97d5");
		$(this).find(".zhul_cy_rclose").show();
	}).mouseout(function(){		
		$(this).find(".zhul_ft_zshu a").css("color","#999999");
		$(this).find(".zhul_cy_rclose").hide();
	});
	/*成员申请hover*/
	$(".zhul_cy_sqlb").each(function(){
		var ly_height=$(this).find(".zhul_cy_lytit").height();
		if (ly_height > 21) {
			$(this).find(".zhul_cy_lytit").css("height", "20px").css("overflow", "hidden");
			$(this).find(".zhul_cy_rmore").show();
		}else{
			$(this).find(".zhul_cy_rmore").hide();
		}
	});
	$(".zhul_cy_liebiao li").mouseover(function(){
		$(this).css("z-index","3");
		$(this).find(".zhul_ft_zshu a").css("color","#0c97d5");
		$(this).find(".zhul_cy_sqlb").addClass("zhul_cy_sqhv");
		$(this).find(".zhul_cy_lytit").css("height","auto");
		$(this).find(".zhul_cy_rmore img").attr("src","/img/indeximg/zhul_sq_lymorehv.gif");
	}).mouseout(function(){
		$(this).css("z-index","1");
		$(this).find(".zhul_ft_zshu a").css("color","#999999");
		$(this).find(".zhul_cy_sqlb").removeClass("zhul_cy_sqhv");
		$(this).find(".zhul_cy_lytit").css("height","20px");
		$(this).find(".zhul_cy_rmore img").attr("src","/img/indeximg/zhul_sq_lymore.gif");
	});
	$(".zhul_jr_sqtext").bind('keyup',function(){
		var str= $(".zhul_jr_sqtext").val();
		var num=getStrlen(str);
		var surplus_num=40-num;
		if(surplus_num<0){
			var strs=substr(str,40);
			$(".zhul_jr_sqtext").val(strs);
			surplus_num=0;
		}
		if(surplus_num==40){
			$("#err_show").html('加入理由忘记填写啦~');
		}else{
			$("#err_show").html('');
		}
		$(".zhul_qyzx_shuzi").html(surplus_num);
	});
	/*帖子搜索*/
	$('#bbs_b_search').click(function(){
		var name = $.trim($('#bbs_n_search').val());
		if (!name || name=='搜索帖子'){
			return false;
		}
		document.bbs_f_search.submit();
	});
	$('#user_b_search').click(function(){
		var name = $.trim($('#user_n_search').val());
		if (!name || name=='搜索小组成员'){
			return false;
		}
		document.user_f_search.submit();
	});
	/*交换友情链接弹框hover*/
	$(".zhul_jh_xzlist li").mouseover(function(){
		$(this).find(".zhul_jh_lianjie").css("border","2px solid #a1defa");
		$(this).find(".zhul_jh_check").show();
	}).mouseout(function(){
		$(this).find(".zhul_jh_lianjie").css("border","2px solid #ffffff");
		$(this).find(".zhul_jh_check").hide();
	});
	/*友情链接hover*/
	$(".zhul_lj_youqing").mouseover(function(){
		$(this).css("background","#f8f8f8");
		$(this).find(".zhul_lj_hulve").show();
	}).mouseout(function(){
		$(this).css("background","#ffffff");
		$(this).find(".zhul_lj_hulve").hide();
	});
	/*统计-网友排行*/
	tab_even('wyhot','zhul_tj_sorthv','zhul_wyph_show');
	tab_even('tzhot','zhul_tj_sorthv','zhul_tzph_show');
	
	/*小组主页 导航hover*/
	$(".zhul_zy_fl").mouseover(function(){
		$(".zhul_fl_dh").removeClass("zhul_zy_flhv");
		$(".zhul_fl_dh").find(".zhul_sy_sort").hide();				
		$(".zhul_zy_sortcon").attr("over",1);
		$(this).addClass("zhul_zy_flhv");		
		$(this).find("#zy_flname").removeClass("zhul_zyhv");
		$(this).find(".zhul_zy_sortcon").show();
	}).mouseout(function(){
		$(".zhul_zy_sortcon").attr("over",2);
		var btn=this;
		setTimeout(function(){
			if($(".zhul_zy_sortcon").attr("over")==2){
				$(btn).removeClass("zhul_zy_flhv");
				$(btn).find("#zy_flname").addClass("zhul_zyhv");
				$(btn).find(".zhul_zy_sortcon").hide();
			}
		}, 100);		
	});
	
	/*小组主页 分类hover*/
	$(".zhul_fl_dh").mouseover(function(){		
		$(".zhul_zy_fl").removeClass("zhul_zy_flhv");
		$(".zhul_zy_fl").find(".zhul_zy_sortcon").hide();	
		$(".zhul_sy_sort").attr("over",1);
		$(this).addClass("zhul_zy_flhv");
		$(this).find("#zy_sort").removeClass("zhul_zyhv");
		$(this).find(".zhul_sy_sort").show();
	}).mouseout(function(){
		$(".zhul_sy_sort").attr("over",2);
		var btn=this;
		setTimeout(function(){
			if($(".zhul_sy_sort").attr("over")==2){
				$(btn).removeClass("zhul_zy_flhv");
				$(btn).find("#zy_sort").addClass("zhul_zyhv");
				$(btn).find(".zhul_sy_sort").hide();
			}
		}, 100);		
	});
	$(".zhul_Rnav_dh li a").click(function(){
		$(".zhul_Rnav_dh li a").removeClass("zhul_Rnav_hv");
		$(this).addClass("zhul_Rnav_hv");
	});
		var r_divTop=300;
		var zhul_dh_zytits=$('.zhul_dh_zytit');
			var length=zhul_dh_zytits.length;
		var r_scrollTop=$(document).scrollTop();
		$(window).bind("scroll",function(){
			var zhul_dh_zytits=$('.zhul_dh_zytit');
			var length=zhul_dh_zytits.length;
			var r_scrollTop=$(document).scrollTop();
			if(r_scrollTop>r_divTop){
				$(".zhul_posNav").show();
				if(length<=0) return;
				if(r_scrollTop>=zhul_dh_zytits.last().offset().top-300){
					$(".zhul_Rnav_dh li a").removeClass("zhul_Rnav_hv");
					$(".zhul_Rnav_dh  li:last").find("a").addClass("zhul_Rnav_hv");
					return;
				}
				for(var i=0;i<length-1;i++){
					if(r_scrollTop>=zhul_dh_zytits.eq(i).offset().top -300
					&&	 r_scrollTop<zhul_dh_zytits.eq(i+1).offset().top 
					){
						$(".zhul_Rnav_dh li a").removeClass("zhul_Rnav_hv");
						$(".zhul_Rnav_dh  li:eq("+i+") ").find("a").addClass("zhul_Rnav_hv");
						break;
					}
				}
				
			}else{
				$(".zhul_Rnav_dh li a").removeClass("zhul_Rnav_hv");
				$(".zhul_Rnav_dh  li:nth-child(1) ").find("a").addClass("zhul_Rnav_hv");
				$(".zhul_posNav").hide();
			}
		});
	/*首页发新帖 选择小组切换*/
	$(".zhul_ft_fltab a").click(function(){
		$(".zhul_ft_zyfl").hide();
		$(".zhul_ft_fltab a").removeClass("zhul_ft_flhv");
		$(this).addClass("zhul_ft_flhv");
		var index=$(".zhul_ft_fltab a").index($(this));
		$(".zhul_ft_zyfl:eq("+index+")").show();
		$("#mine_tishi").hide();
		$("#mine").show();
	});
})
/*首页二维码点击*/
function iosApp(){
	$(".zhul_app_adbg").hide();
	$(".zhul_app_iosbg").toggle();
}
function androidApp(){
	$(".zhul_app_iosbg").hide();
	$(".zhul_app_adbg").toggle();
}
/*群组首页tab切换*/
function tab_even(id_name,class_hover,class_con){
	$("#"+id_name+" a").mouseover(function(){
	$("."+class_con).hide();
	$("#"+id_name+" a").removeClass(class_hover);
	$(this).addClass(class_hover);
	var index=$("#"+id_name+" a").index($(this));
		$("."+class_con+":eq("+index+")").show();      
	});
}
/*选择分类 弹框*/
function userData(divid,maxnum){
	var divid = parseInt(divid);
	$("#zindex"+divid).css("z-index","10");
	$("#boxDiv"+divid).show();
	if(divid==1){
		for(e=1;e<=maxnum;e++){
			$("#boxDiv"+e).hide();
			$("#zindex"+e).css("z-index","3");
		}
		$(".zhul_new_dqbox").hide();
		$("#zindex"+divid).css("z-index","10");
		$("#boxDiv"+divid).show();
		
	}else if(divid>1 && divid<maxnum){
		$(".zhul_new_dqbox").hide();
		for(b=1;b<divid;b++){
			$("#boxDiv"+b).hide();
			$("#zindex"+b).css("z-index","3");
		}
		for(d=1;d<=maxnum;d++){
			$("#boxDiv"+d).hide();
			$("#zindex"+d).css("z-index","3");
		}
		$("#zindex"+divid).css("z-index","10");
		$("#boxDiv"+divid).show();
	}else if(divid == maxnum){
		for(c=1;c<maxnum;c++){
			$("#boxDiv"+c).hide();
			$("#zindex"+c).css("z-index","3");
		}
		$("#zindex"+divid).css("z-index","10");
		$("#boxDiv"+divid).show();
	}
}
/*弹框 关闭*/
function closeUserBox(divid){
	$(".zhul_cj_flBox").hide();
	$("#zindex"+divid).css("z-index","3");
	$("input[type='text']").show();
}
function changeimgcode(){
	$("#seccodeimg").attr("src","/seccode/index?"+Math.random()); 
}
function applyaddgroup(gid,group_name,fid,refid){
	var cause=$(".zhul_jr_sqtext").val();
	if(!cause){
		$("#err_show").html('加入理由忘记填写啦~');
		return;
	}
	$.post("/user/applyaddgroup",{gid:gid,group_name:group_name,fid:fid,refid:refid,cause:cause},function(result){
		var data=eval("("+result+")");
		if(data.errNo==0){
			tb_remove();
			reviewSuccess_height('申请发送成功,请耐心等待组长审核…');
			setTimeout('window.location.reload();',3000);
		}else if(data.errNo==2204){
			tb_remove();
			reviewError(data.msg);
			setTimeout('window.location.reload();',3000);
		}else{
			changeimgcode();
			reviewError(data.msg);
		}
	});	
}
function getEvent() //同时兼容ie和ff的写法
    { 
        if(document.all)  return window.event;   
        func=getEvent.caller;       
        while(func!=null){ 
            var arg0=func.arguments[0];
            if(arg0)
            {
              if((arg0.constructor==Event || arg0.constructor ==MouseEvent) || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation))
              { 
              return arg0;
              }
            }
            func=func.caller;
        }
        return null;
    }
//加入小组公开组的话
function addgroup(gid,group_name,referrer_uid,callback){
	var evt = getEvent(); 
	if(evt && typeof evt.target !="undefined"){
		if($(evt.target).attr("disable")==1){
			return;
		}
		$(evt.target).attr("disable",1);
	}
	$.post("/user/addGroup",{gid:gid,group_name:group_name,refid:referrer_uid},function(result){
		if(evt && typeof evt.target !="undefined"){
			$(evt.target).removeAttr("disable");
		}
		var data=eval("("+result+")");
		if(data.errNo==0){
			if(typeof callback=="function"){
				callback();
			}else{
				reviewSuccess('加入成功！');
				window.location.reload(); 
			}
		}else{
			if(data.errNo==-1){
				pubMsgbox('申请加入','430','290','joinGroup');
			}else{
				if(data.msg.indexOf('vip')>-1){
					reviewSuccess('VIP会员可以加入该组，快去升级吧~')
				}else if(data.msg.indexOf('您还未认证')>-1){
					reviewSuccess('实名认证会员可以加入该组，快去完成实名认证吧~')
				}else{
					reviewError(data.msg);
				}
			}
		}
	});	
}
function quitGroup(gid,uid){
	$.post("/user/quitgroup",{gid:gid,uid:uid},function(result){
		var data=eval("("+result+")");
		if(data.errNo==0){
			tb_remove();
			reviewSuccess('退出成功！');
			window.location.reload(); 
		}else if(data.errNo==2211){
			tb_remove();
			reviewError('请先退出管理团队！');
		}
	});	
}
//计算私信内容数
function bbs_checkMsgContentWordCount(divid,max, isForm) {
    var msgContent = $("#" + divid+" textarea").val();
	msgContent=htmlspecialchars(msgContent);
    if (msgContent == "") {
        $(".zhul_qyzx_shuzi").html(max);
        $("#" + divid + " .zhul_errormsg").html("内容不能为空");
        return false;
    }
    var len = msglen(msgContent);
    if (len > max) {
        $(".zhul_qyzx_shuzi").html(0);
        $("#" + divid + " .zhul_errormsg").html("内容多了" +( len-max) + "个字");
        return false;
    } else {
        $(".zhul_qyzx_shuzi").html((max - len));
        $("#" + divid + " .zhul_errormsg").html();
        if (len == 0) {
            if (isForm) {
                $("#" + divid + " .zhul_errormsg").html("请输入内容");
            }
            return false;
        }
    }
    $("#" + divid + " .zhul_errormsg").html("");
    return true;
}
//私信提交表单 
function bbs_submitForm(divid,max, touid) {
    var msgContent = $("#" + divid + " textarea").val();
	msgContent=htmlspecialchars(msgContent);
    if (msgContent == "") {
        $("#" + divid + " .zhul_errormsg").html("内容不能为空");
        return false;
    }
    var len = msglen(msgContent);
    if (len >= max) {
        $(".zhul_qyzx_shuzi").html(0);
        $("#" + divid + " .zhul_errormsg").html("内容多" + (len-max) + "个字");
        return false;
    } else {
        $(".zhul_qyzx_shuzi").html((max - len));
        $("#" + divid + " .zhul_errormsg").html();
        if (len == 0) {
            $("#" + divid + " .zhul_errormsg").html("内容不能为空");
            return false;
        }
    }
    $("#" + divid + " .zhul_errormsg").html("");
    if ($("#TB_ajaxContent .zhul_glbz_fsbtnHv").attr("disable") == 1) {
        return;
    }
    var username = $("#" + divid + " .msg_uname").html();
    $("#TB_ajaxContent .zhul_glbz_fsbtnHv").attr("disable", 1);
    $.getJSON(ucenter_domain + 'openjson/sendmsg?action=sendmsg&ajax=1&callback=?', { uid: touid, msgContent: msgContent, username: username }, function (data) {
        $("#" + divid + " .zhul_glbz_fsbtnHv").removeAttr("disable");
        if (data.errNo == 0) {
            reviewSuccess('发表成功');
            tb_remove();
        } else {
            $("#" + divid + " .zhul_errormsg").html(data.msg);
        }

    });
    return true;
}
//展开分享
function wx_share(){
	$(".zhul_po_wxkuang").show();
}
//关闭分享
function gb_share(){
	$(".zhul_po_wxkuang").hide();
}
var Dragging=function(validateHandler){ //参数为验证点击区域是否为可移动区域，如果是返回欲移动元素，负责返回null
    var draggingObj=null; //dragging Dialog
    var diffX=0;
    var diffY=0;
    
    function mouseHandler(e){
        switch(e.type){
            case 'mousedown':
                draggingObj=validateHandler(e);//验证是否为可点击移动区域
                if(draggingObj!=null){
                	var left=parseInt($(draggingObj).css("margin-left"));
                	var top=parseInt($(draggingObj).css("margin-top"));
                    diffX=e.clientX-left;
                    diffY=e.clientY-top;
                }
                break;
            
            case 'mousemove':
                if(draggingObj){

                	$(draggingObj).css("margin-left",e.clientX-diffX+'px');
                   	$(draggingObj).css("margin-top",e.clientY-diffY+'px');
                }
                break;
            
            case 'mouseup':
                draggingObj =null;
                diffX=0;
                diffY=0;
                break;
        }
    };
    
    return {
        enable:function(){
        	try{
	            document.addEventListener('mousedown',mouseHandler);
	            document.addEventListener('mousemove',mouseHandler);
	            document.addEventListener('mouseup',mouseHandler);
        	}catch(e){
	            document.attachEvent('onmousedown',mouseHandler); 
	            document.attachEvent('onmousemove',mouseHandler); 
	            document.attachEvent('onmouseup',mouseHandler); 
        	}
        },
        disable:function(){
        	try{
	            document.removeEventListener('mousedown',mouseHandler);
	            document.removeEventListener('mousemove',mouseHandler);
	            document.removeEventListener('mouseup',mouseHandler);
        	}catch(e){
        		document.detachEvent('onmousedown',mouseHandler); 
	            document.detachEvent('onmousemove',mouseHandler); 
	            document.detachEvent('onmouseup',mouseHandler);        		
        	}
        }
    }
}

function getDraggingDialog(e){
    var target=e.target || e.srcElement;
    while(target && target.id.indexOf('TB_title')==-1){
        target=target.offsetParent;
    }
    if(target!=null){
        return target.offsetParent;
    }else{
        return null;
    }
}
$(".zhul_qz_appewm li").live('mouseover',function(){
	$(this).find('p').show();
});
$(".zhul_qz_appewm li").live('mouseout',function(e){
	$(this).find('p').hide();
});
function newaddgroup(gid,group_name,referrer_uid,callback){
	if($.cookie('uid')>0){
		addgroup(gid,group_name,referrer_uid,callback);
	}else{
		widow_Loading();return;
	}
}

//发帖跳转
function newaddthread(gid){
	if($.cookie('uid')>0){
		$.post("/thread/detectadd",{gid:gid},function(result){
			var data=eval("("+result+")");
			if(data.errNo==0){
				window.location.href=data.result+"addtopic";
			}else if(data.errNo==-2){
				/*newaddgroup(gid,data.group_name,0,function(){
					newaddvote(gid)
				});*/
				reviewError('本小组需要加入才可以发帖');
			}else{
				reviewError(data.msg);
			}
		});	
	}else{
		widow_Loading();return;
	}
}
//发投票跳转
function newaddvote(gid){
	if($.cookie('uid')>0){
		$.post("/thread/detectadd",{gid:gid},function(result){
			var data=eval("("+result+")");
			if(data.errNo==0){
				window.location.href=data.result+"addvote";
			}else if(data.errNo==-2){
				reviewError('本小组需要加入才可以发帖');
				/*newaddgroup(gid,data.group_name,0,function(){
					newaddvote(gid)
				});*/
			}else{
				reviewError(data.msg);
			}
		});
	}else{
		widow_Loading();return;
	}
}


